﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace ChoJu.Single.DAL
{
    public class LocationDal
    {
        public GeoLocation GetLocationByIP()
        {
            using (WebClient client = new WebClient())
            {
                string json = client.DownloadString("http://ip-api.com/json/");
                return JsonConvert.DeserializeObject<GeoLocation>(json);
            }
        }
    }

    public class GeoLocation
    {
        public string Query { get; set; }
        public string Country { get; set; }
        public string RegionName { get; set; }
        public string City { get; set; }
        public double Lat { get; set; }
        public double Lon { get; set; }
    }
}
